import multiprocessing

"""
消息队列,先进先出原则
"""
def sed_data(q):
    # 模拟放入数据
    data = [1, 2, 3, 4]
    for i in data:
        q.put(i)
    print('[+]数据放入')


def accept_data(q):
    # 模拟取数据
    l = list()
    while True:
        data_get = q.get()
        l.append(data_get)
        if q.empty():
            break
        print('[放入数据为]',data_get)


def main():
    # 创建队列
    q = multiprocessing.Queue()

    # 创建进程
    p1 = multiprocessing.Process(target=sed_data, args=(q,))
    p2 = multiprocessing.Process(target=accept_data, args=(q,))

    # 启动
    p1.start()
    p2.start()


if __name__ == '__main__':
    main()
